package com.sxj.corejava.code07_面向对象.多态与常量;

import java.util.Scanner;

/**
 * @author 石小俊
 * 2024年07月16日 11:24
 */
public class Test02_练习 {

    public static void main(String[] args) {
        showMenu();
    }

    public static void showMenu() {
        Scanner sc = new Scanner(System.in);
        System.out.println("********************欢迎来到紫金宠物店********************");
        System.out.print("请选择需要领养的宠物(1.狗 2.猫 3.猪):");
        Pet pet = new Pet();
        int choice = sc.nextInt();
        switch (choice) {
            case 1:
                pet = new Dog("来福", "公", 3);
                pet.show();
                break;
            case 2:
                pet = new Cat("汤姆", "公", "蓝");
                pet.show();
                break;
            case 3:
                pet = new Pig("佩琪", "母", "跳泥坑");
                pet.show();
                break;
            default:
                System.out.println("错误:您输入的选项有误,请重新输入");
                break;
        }

    }

}

class Pet {
    private String name;
    private String gender;

    public void show() {
        System.out.println("这是一只宠物");
    }

    public Pet() {
    }

    public Pet(String name, String gender) {
        this.name = name;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}

class Dog extends Pet {
    private int age;

    public void show() {
        System.out.println("这是一只叫做" + super.getName() + "的宠物狗,性别:" + getGender() + ",年龄:" + age);
    }

    public Dog(String name, String gender, int age) {
        super(name, gender);
        this.age = age;
    }

    public Dog() {
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Cat extends Pet {
    private String type;

    public void show() {
        System.out.println("这是一只叫做" + super.getName() + "的" + type + "猫,性别:" + getGender());
    }

    public Cat(String name, String gender, String type) {
        super(name, gender);
        this.type = type;
    }

    public Cat() {
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

class Pig extends Pet {
    private String hobby;

    public void show() {
        System.out.println("这是一只叫做" + super.getName() + "的宠物猪,性别:" + getGender() + ",爱好:" + hobby);
    }

    public Pig(String name, String gender, String hobby) {
        super(name, gender);
        this.hobby = hobby;
    }

    public Pig() {
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }
}